package json;

import com.eksframework.commons.json.EksJson;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializationFeature;
import json.bean.FilmTicketInfo;

import java.io.IOException;
import java.util.Collections;
import java.util.List;

/**
 * Main
 *
 * @author: chenfenghai
 * @version: 1.0
 * @date: 2020-05-09 14:28
 * @blame Team
 */
public class Main {

    public static void main(String[] args) throws IOException {
        FilmTicketInfo info = FilmTicketInfo.builder()
                .cinemaCode("8888888")
                .cinemaName("广州影院")
                .build();
        String json = EksJson.toJson(info);
        System.out.println(json);
        String jsonArray = EksJson.toJson(Collections.singletonList(info));
        System.out.println(jsonArray);
        System.out.println(EksJson.createEksJackson()
                .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
                .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
                .enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)
                .setSerializationInclusion(JsonInclude.Include.NON_NULL)
                .toJson(info));
        String jsonArray2 = EksJson.createEksJackson()
                .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
                .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
                .enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)
                .setSerializationInclusion(JsonInclude.Include.NON_NULL)
                .toJson(Collections.singletonList(info));
        System.out.println(jsonArray2);
        JsonNode jsonNode = EksJson.parseObject(json);
        FilmTicketInfo ticketInfo = EksJson.parseObject(jsonNode, FilmTicketInfo.class);
        System.out.println(ticketInfo.getCinemaName());

        List<FilmTicketInfo> list = EksJson.parseArray(jsonArray, FilmTicketInfo.class);
        System.out.println(list.get(0).getCinemaName());

        list = EksJson.parseArray(jsonArray2, FilmTicketInfo.class);
        System.out.println(list.get(0).getCinemaName());
    }
}
